% TEST_ID: LANG-EXPAND-0056
% CATEGORY: language/function_handle
% 测试匿名函数

function test_lambda_function
    A = 2;
    f = @(x) x + A;
    r = call_f(f, 1);
    assert(isequal(r, 3));
    [a f] = innerDynFunc();
    assert(isequal(a, 102))
    assert(isequal(f(100), 200));
    [~, f, g] = innerDynFunc();

    assert(isequal(g(), 10));

    x = 1;
    f = @() x + 1;
    y = f()
    assert(isequal(y, 2))
    x = 10;
    y = f()
    % lambda 会捕获变量
    assert(isequal(y, 2))
end





function r = call_f(f, x)
    r = f(x);
end

function [az, af, ag] = innerDynFunc()
    A = 100;
    f = @(x) A + x;

    z = f(2);

    g = @() nested_script_fn;

    function AA = nested_script_fn
        AA = 10;
    end

    az = z;
    af = f;
    ag = g;
end